package org.sheep;

import org.sheep.GameView.GameThread;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;

public class Game extends Activity{
    //Menu Options
    private static final int MENU_RESUME = 1;
    private static final int MENU_RESTART = 2;
    private static final int MENU_SAVE = 3;
    private static final int MENU_STOP = 4;
    private static final int MENU_HELP = 5;
    
    private GameThread thread;
    
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		
		Log.i("Game", "A new Activity has been born!");
		
		setContentView(R.layout.game);
		
    thread = ((GameView) findViewById(R.id.game)).getThread();
    
   // if(savedInstanceState == null) {
      thread.ready();
      //thread.start();
      Log.i("Game", "GameThread Ready");
    /*} else {
      thread.restore(savedInstanceState);
    }*/
	}
	
    @Override
    protected void onPause() {
        super.onPause();
        thread.pause();
    }
    
    @Override
    protected void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        thread.save(outState);
    }
    
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        super.onCreateOptionsMenu(menu);

        menu.add(0, MENU_RESUME, 0, R.string.menu_resume);
        menu.add(0, MENU_RESTART, 0, R.string.menu_restart);
        menu.add(0, MENU_SAVE, 0, R.string.menu_save);
        menu.add(0, MENU_STOP, 0, R.string.menu_stop);
        menu.add(0, MENU_HELP, 0, R.string.menu_help);
        return true;
    }
    
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
    	Log.w("Option", "ID: " + item.getItemId());
        switch (item.getItemId()) {
            case MENU_RESTART:
                thread.stop();
                thread.ready();
                return true;
            case MENU_SAVE:
                thread.save();
                return true;
            case MENU_STOP:
                thread.stop();
                return true;
            case MENU_HELP:
                thread.pause();
                //call help view
                return true;
        }

        return false;
    }
}
